package org.uim.cricket.analyzer.parsers.bowling.impl;

import java.util.ArrayList;
import java.util.List;

import org.uim.cricket.analyzer.parsers.bowling.AbstractBowlingInningsParser;
import org.uim.cricket.analyzer.parsers.bowling.BowlingInningParsable;
import org.uim.cricket.entities.aggr.SingleInning;
import org.uim.cricket.entities.bowling.BowlingInning;
import org.uim.cricket.util.MyStringUtils;

public class BowlingInningsParser extends AbstractBowlingInningsParser {

    public static String BOWLING_HEADER_STARTER = "<tr class=\"inningsHead\">";
    public static String BOWLING_INNING_STARTER = "<tr class=\"inningsRow\">";
    
    public BowlingInningsParser(BowlingInningParsable theBowlingParsable) {
        super(theBowlingParsable);
    }

    @Override
    public List<BowlingInning> parseAllBowlingInnings(StringBuilder sb, SingleInning inning) {
        ArrayList<BowlingInning> bowls = new ArrayList<BowlingInning>();
        
        String[] rows = MyStringUtils.splitInBetween(sb.toString(), BOWLING_INNING_STARTER, "</tr>");
        
        for (int i=0; i<rows.length; i++) {
            BowlingInning bowlinn = super.getBowlingParsable().parseBowlingInning(new StringBuilder(rows[i])); 
            if (bowlinn != null) {
                bowls.add(bowlinn);
            }
        }
        
        return bowls;
    }

	
	
}
